package fz.vrd.app.toast_dialog;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RadioGroup;

import java.util.ArrayList;

import fz.vrd.app.BaseMyAc;
import fz.vrd.app.R;
import fz.vrd.library.page.activity.BaseAc;
import fz.vrd.ui.dialog.DialogFactory;
import fz.vrd.ui.dialog.listener.CheckItemsCallBack;
import fz.vrd.ui.dialog.listener.OkOrCancleClickListener;
import fz.vrd.ui.dialog.listener.OneBtnClickListern;
import fz.vrd.ui.toast.ToastFactory;

/**
 * @类说明：dialog
 * @创建者： VinRichard  2025/3/24/024
 * @备注：
 */
public class DialogAc extends BaseMyAc implements View.OnClickListener {

    boolean isSys = true;

    ProgressBar bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        getSupportActionBar().setTitle("对话框");

        findViewById(R.id.btn_load).setOnClickListener(this);
        findViewById(R.id.btn_one).setOnClickListener(this);
        findViewById(R.id.btn_two).setOnClickListener(this);
        findViewById(R.id.btn_edit).setOnClickListener(this);
        findViewById(R.id.btn_more).setOnClickListener(this);
        findViewById(R.id.btn_list).setOnClickListener(this);
        findViewById(R.id.btn_pop).setOnClickListener(this);

        bar = findViewById(R.id.bar);


        ((RadioGroup) findViewById(R.id.rgp)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                isSys = i == R.id.rb_sys;
            }
        });
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.btn_load:
                if (isSys) {
                    bar.setVisibility(View.VISIBLE);
                } else {
                    DialogFactory.loadDialog(page.getActivity(), "加载5秒后消失");
                }
                break;
            case R.id.btn_one:
                if (isSys) {
                    new AlertDialog.Builder(page.getContext()).setTitle("提示").setMessage("是否确定")
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了");
                                }
                            }).show();
                } else {
                    DialogFactory.showOneBtnDialog(page.getActivity(), "点击确定", new OneBtnClickListern() {
                        @Override
                        public void callBack() {
                            toast("点击了");
                        }
                    });
                }
                break;
            case R.id.btn_two:
                if (isSys) {
                    new AlertDialog.Builder(page.getContext()).setTitle("提示").setMessage("是否确定")
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 确定");
                                }
                            })
                            .setPositiveButton("再想想", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 再想想");
                                }
                            })
                            .show();
                } else {
                    DialogFactory.showTwoBtnDialog(page.getActivity(), "提示", "是否提交", "提交", "再想想", new OkOrCancleClickListener() {
                        @Override
                        public void callBack(boolean isOk) {
                            toast("点击了" + (isOk ? "提交" : "再想想"));
                        }
                    });
                }
                break;
            case R.id.btn_edit:
                if (isSys) {
                    View view1 = LayoutInflater.from(getContext()).inflate(R.layout.view_edit, null);
                    new AlertDialog.Builder(page.getContext())
                            .setTitle("提示")
                            .setView(view1)
                            .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    String info = ((EditText) view1.findViewById(R.id.et)).getText().toString();
                                    toast("点击了 " + info);
                                }
                            })
                            .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("取消了");
                                }
                            })

                            .show();
                } else {
                    toast("没有了");
                }
                break;
            case R.id.btn_more:
                if (isSys) {
                    new AlertDialog.Builder(page.getContext()).setTitle("提示").setMessage("是否确定")
                            .setNegativeButton("登录", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 登录");
                                }
                            })
                            .setPositiveButton("注册", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 注册");
                                }
                            })
                            .setNeutralButton("关闭", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 关闭");
                                }
                            })
                            .show();
                } else {
                    toast("没有的");
                }
                break;
            case R.id.btn_list:
                if (isSys) {
                    new AlertDialog.Builder(page.getContext())
                            .setTitle("提示")
                            .setItems(new String[]{"111", "2222", "3333"}, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    toast("点击了 " + i);
                                }
                            }).show();
                } else {
                    ArrayList list = new ArrayList();
                    list.add("111");
                    list.add("2222");
                    list.add("3333");
                    list.add("4444");
                    DialogFactory.showCheckItemsDialog(page.getActivity(), list, new CheckItemsCallBack() {
                        @Override
                        public void callBack(int index, String msg) {
                            toast(index + "点击了 " + msg);
                        }
                    });
                }

                break;

            case R.id.btn_pop:
                PopupWindow popupWindow = new PopupWindow();
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View contentView = inflater.inflate(R.layout.popup_window, null);
                popupWindow.setContentView(contentView);
                popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置宽度
                popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置高度
                popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // 设置背景为透明
                popupWindow.setOutsideTouchable(true); // 点击外部区域使PopupWindow消失
                popupWindow.showAsDropDown(view);
                break;
        }
    }
}